
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
    #region Producttag Model -(by fangyifeng at 2010-12-05 13:59:31)

    /// <summary>
    /// Producttag object'producttags'.
    /// </summary>
    public class Producttag : System.IComparable
    {
        #region Member Variables

        protected Guid _id;
        protected string _tagname;
        protected DateTime _createDate;
        protected string _beginLetter;

        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public Producttag() { }

        public Producttag(string tagname, DateTime createDate, string beginLetter)
        {
            this._tagname = tagname;
            this._createDate = createDate;
            this._beginLetter = beginLetter;
        }

        #endregion

        #region Public Properties

        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string Tagname
        {
            get { return _tagname; }
            set
            {
                if (value != null && value.Length > 30)
                    throw new ArgumentOutOfRangeException("Invalid value for Tagname", value, value.ToString());
                _tagname = value;
            }
        }

        public virtual DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }

        public virtual string BeginLetter
        {
            get { return _beginLetter; }
            set
            {
                if (value != null && value.Length > 10)
                    throw new ArgumentOutOfRangeException("Invalid value for BeginLetter", value, value.ToString());
                _beginLetter = value;
            }
        }

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is Producttag))
                throw new InvalidCastException("This object is not of type Producttag");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((Producttag)obj).Id);
                    break;
                case "Tagname":
                    relativeValue = this.Tagname.CompareTo(((Producttag)obj).Tagname);
                    break;
                case "CreateDate":
                    relativeValue = this.CreateDate.CompareTo(((Producttag)obj).CreateDate);
                    break;
                case "BeginLetter":
                    relativeValue = this.BeginLetter.CompareTo(((Producttag)obj).BeginLetter);
                    break;
                default:
                    goto case "Id";
            }
            if (Producttag.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
